package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        try (
                Connection a=DBUtil.getConnection();
             ){
            Statement rs=a.createStatement();//执行语句对象
            String sql="SELECT t.name,t.salary,t.title,c.name,c.floor  " +
                       "FROM teacher t " +
                       "JOIN class c ON c.teacher_id=t.id " +
                       "WHERE t.name='王克晶' ";
            ResultSet s=rs.executeQuery(sql);
            while (s.next()){
                String tName=s.getString("t.name");
                int salary=s.getInt("t.salary");
                String title=s.getString("t.title");
                String cName=s.getString("c.name");
                int floor=s.getInt("c.floor");
                System.out.println(tName+" "+salary+" "+title+" "+cName+" "+floor);
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
